/**
 * 选择器： 单选
 */
import React from 'react'
// prettier-ignore
import {
  View,
  StyleSheet,
} from 'react-native'

import PickerProps from '../core/PickerProps'
import {RXSinglePicker} from 'react-native-rxpicker'

const SinglePicker = props => {
  // prettier-ignore
  const {title, list, selectValue, onChangeText, dismiss, onConfirm, _superCallBack, ...other} = props
  // console.log('SinglePicker - list=', list, onChangeText)
  return (
    <View style={styles.container}>
      <RXSinglePicker
        {...other}
        style={{flex: 1}}
        title={title}
        list={list}
        selectValue={selectValue}
        dismiss={() => {
          dismiss && dismiss()
          _superCallBack && _superCallBack(0)
        }}
        onConfirm={result => {
          // 按照 需求自定义
          if (result === selectValue) {
            console.log('当前选择，是上一次的结果，不可点击确定')
            _superCallBack && _superCallBack(-1)
            return
          }
          onChangeText && onChangeText(result)
          _superCallBack && _superCallBack(1)
          onConfirm && onConfirm()
        }}
      />
    </View>
  )
}

SinglePicker.prototype = PickerProps.singleProps.prototype
SinglePicker.defaultProps = PickerProps.singleProps.defaultProps
export default SinglePicker

const styles = StyleSheet.create({
  container: {
    width: '100%',
    margin: 0,
    padding: 0,
    backgroundColor: '#fff',
    marginBottom: 20,
  },
})
